package hotspot;

import comms.Communicator;

/**
 * Describes a hotspot as a piece of text
 * Assigned the last position updated from the Kinect 
 * and next hotspot id
 *  
 * @author norrielm
 */
public class Hotspot {

	private int hotspotRange = 50; //150
	private int id;
	private String text;
	protected double[] pos = new double[3];

	public Hotspot(int i, String s, double[] p){
		setId(i);
		setText(s);
		pos = p.clone();
	}

	public boolean compare(double[] p){
		//System.out.println("dif of "+this.toString());
		//System.out.println(String.format("dif  (%f,%f,%f)",pos[0] - p[0], pos[1] - p[1], pos[2] - p[2]));

		if(	//check all < maxRange
			(pos[0] - p[0])/1000 < hotspotRange &&
			(pos[1] - p[1])/1000 < hotspotRange &&
			(pos[2] - p[2])/1000 < hotspotRange &&
			//check all > minRange
			(pos[0] - p[0])/1000 > -hotspotRange &&
			(pos[1] - p[1])/1000 > -hotspotRange &&
			(pos[2] - p[2])/1000 > -hotspotRange 
		  )
			return true;
		
		return false;
	}

	public double compareMin(double[] p){
		//System.out.println("dif of "+this.toString());
		double difA = (p[0] - pos[0])/1000; //in mm
		double difB = 0;//(p[1] - pos[1])/1000;
		double difC = (p[2] - pos[2])/1000;
		double dif = difA - difB - difC;
		//Communicator.c.append(String.format("dif %d ( %f , %f , %f ) = %f ",id, difA,difB,difC,dif));

		return  dif;
	}
	
	public double compareX(double[] p){
		return (p[0] - pos[0])/1000; //in mm
	}
	
	public double compareZ(double[] p){
		return (p[2] - pos[2])/1000; //in mm
	}
	
	public int hashCode(){
		return (int) (pos[0] + pos[1] + pos[2]);
	}
	
	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}
	
	public double getX(){
		return pos[0];
	}
	
	public double getY(){
		return pos[1];
	}
	
	public double getZ(){
		return pos[2];
	}
	

	public void setText(String text) {
		this.text = text;
	}

	public String getText() {
		return text;
	}

	public String toString(){
		return String.format("spot %d (%f,%f,%f) %s ",
								   id, pos[0],pos[1],pos[2], text);
	}
}
